package com.ytzl.itrip.service.impl;

import com.ytzl.itrip.dao.ItripLabelDicMapper;
import com.ytzl.itrip.service.ItripLabelDicService;
import com.ytzl.itrip.pojo.ItripLabelDic;
import com.ytzl.itrip.common.EmptyUtils;
import com.ytzl.itrip.common.Constants;
import com.ytzl.itrip.common.Page;
import com.ytzl.itrip.vo.ItripLabelDicVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ItripLabelDicServiceImpl implements ItripLabelDicService {

    @Resource
    private ItripLabelDicMapper itripLabelDicMapper;

    public ItripLabelDic getItripLabelDicById(Long id) throws Exception {
        return itripLabelDicMapper.getItripLabelDicById(id);
    }

    public Integer removeItripLabelDicById(Long id) throws Exception {
        return itripLabelDicMapper.removeItripLabelDicById(id);
    }

    public List<ItripLabelDic> getItripLabelDicListByMap(Map
                                                                 <String, Object> param) throws Exception {
        List<ItripLabelDic> list = itripLabelDicMapper.getItripLabelDicListByMap(param);
        return list;
    }

    public Integer getItripLabelDicCountByMap(Map
                                                      <String, Object> param) throws Exception {
        return itripLabelDicMapper.getItripLabelDicCountByMap(param);
    }

    public Integer saveItripLabelDic(ItripLabelDic itripLabelDic) throws Exception {
        itripLabelDic.setCreationDate(new Date());
        return itripLabelDicMapper.saveItripLabelDic(itripLabelDic);
    }

    public Integer modifyItripLabelDic(ItripLabelDic itripLabelDic) throws Exception {
        itripLabelDic.setModifyDate(new Date());
        return itripLabelDicMapper.modifyItripLabelDic(itripLabelDic);
    }

    public Integer removeItripLabelDicByIds(Long[] ids) throws Exception {
        return itripLabelDicMapper.removeItripLabelDicByIds(ids);
    }

    @Override
    public List<ItripLabelDicVO> getItripLabelDicByParentId(Long parentId) throws Exception {
        return itripLabelDicMapper.getItripLabelDicByParentId(parentId);
    }

    public Page<ItripLabelDic> queryItripLabelDicPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = itripLabelDicMapper.getItripLabelDicCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<ItripLabelDic> itripLabelDicList = itripLabelDicMapper.getItripLabelDicListByMap(param);
        page.setRows(itripLabelDicList);
        return page;
    }

}
